home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / language / awe / awe-full.lha / Awe2 / DoNotUseThisSrc / SingleCpuMux.cc < prev    next >
C/C++ Source or Header  |  1990-08-08  |  2KB  |  126 lines

  1. // This may look like C code, but it is really -*- C++ -*-
  2. // 
  3. // Copyright (C) 1988 University of Illinois, Urbana, Illinois
  4. //
  5. // written by Dirk Grunwald (grunwald@cs.uiuc.edu)
  6. //
  7.  
  8. #ifdef __GNUG__
  9. #  pragma implementation
  10. #endif
  11.  
  12. #include "SingleCpuMux.h"
  13. #include "CpuMultiplexorP.h"
  14. #include "SpinLock.h"
  15. #include "SpinFetchAndOp.h"
  16. #include "Thread.h"
  17. #include "ThreadContainer.h"
  18. #include "ReserveByException.h"
  19. #include "HardwareContextP.h"
  20. #include <math.h>
  21.  
  22. //
  23. //    This can not be private, or we wont see all the action
  24. //
  25.  
  26. SingleCpuMux::SingleCpuMux(int debug) : (debug)
  27. {
  28.     ThisCpu = this;
  29.     CpuMuxDebugFlag = debug;
  30.     pNameTemplate = "SingleCpuMux";
  31.     sprintf(nameSpace, "[%s-%d] ", pNameTemplate, iYam);
  32.     pName = nameSpace;
  33. }
  34.  
  35. SingleCpuMux::~SingleCpuMux()
  36. {
  37. }
  38.  
  39. void
  40. SingleCpuMux::allocateLocalEventStructures(int newIYam, int outOf)
  41. {
  42.     assert( newIYam == 0 && outOf == 1 );
  43.  
  44.     iYam = newIYam;
  45.     sprintf(nameSpace, "[%s-%d] ", pNameTemplate, iYam);
  46.     pName = nameSpace;
  47.  
  48.     myCurrentEvents = AllocateHardwareCurrentEventsStructure();
  49. }
  50.  
  51. void
  52. SingleCpuMux::allocateEventStructures(int newIYam, int outOf)
  53. {
  54.     allocateLocalEventStructures(newIYam, outOf);
  55. }
  56.  
  57. void
  58. SingleCpuMux::deallocateEventStructures()
  59. {
  60.     delete myCurrentEvents;
  61.     myCurrentEvents = 0;
  62. }
  63.  
  64. void
  65. SingleCpuMux::fireItUp(int, unsigned)
  66. {
  67.     warmThePot(1);
  68.     stirItAround();
  69.     coolItDown();
  70. }
  71.  
  72. void
  73. SingleCpuMux::warmThePot(int)
  74. {
  75.     pid = getpid();
  76.     enabled = 1;
  77. }
  78.  
  79. void
  80. SingleCpuMux::coolItDown()
  81. {
  82.     // empty
  83. }
  84.  
  85. void
  86. SingleCpuMux::add(Thread *who)
  87. {
  88.     addUnlocked( who );
  89. }
  90.  
  91. Thread *
  92. SingleCpuMux::remove()
  93. {
  94.     //
  95.     //    System stopped?
  96.     //
  97.     if ( *terminated ) {
  98.     return(0);
  99.     }
  100.     return( myCurrentEvents -> remove() );
  101. }
  102.  
  103. //
  104. // This is the job dispatcher.
  105. //
  106.  
  107. void
  108. SingleCpuMux::stirItAround()
  109. {
  110.     currentThread = 0;
  111.  
  112.     while( ! *terminated ) {
  113.     //
  114.     //    remove directly instead of calling remove
  115.     //
  116.     currentThread = myCurrentEvents -> remove();
  117.  
  118.     if (currentThread == 0 ) {
  119.         return;
  120.     }
  121.     systemContext.switchContext(&(currentThread -> pContext));
  122.     raisedBy -> handleException();
  123.     raisedBy = 0;
  124.     }
  125. }
  126.